package cn.itlaobing.dao;

import cn.itlaobing.model.Station;
import cn.itlaobing.model.StationDto;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * 列车车次的数据访问类
 * Created by xuaner on 2017/11/10.
 */
public class StationDao extends BaseDao {
    public StationDto query(String trainNum, String station1, String station2)throws SQLException,ClassNotFoundException{
        String sql="select * from (SELECT t1.trainNum trainNum,t1.station start,t2.station end,ABS(t1.sitePrice-t2.sitePrice) price " +
                "FROM station t1 ,station t2   WHERE t1.trainNum=? AND t2.trainNum =? AND " +
                "t1.station=? AND t2.station=?)s1";
        QueryRunner qr=new QueryRunner(getDataSource());
        BeanHandler<StationDto> list=new BeanHandler<StationDto>(StationDto.class);
        return qr.query(sql,list,trainNum,trainNum,station1,station2);
    }
}
